<?php
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
// DLMan by Shedd Technologies International		  				//
// http://www.dlman.com | info@dlman.com							//
// Copyright 2003 by STI, All rights reserved.						//
// ---------------------------------------------------------------- //
// Usage of this software is governed by the terms of GPL. 	    	//
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

require_once("../global.php");
require_once("../uis.php");
require_once("../config.php");
require_once("../functions.php");

//DISPLAY LOGIN SCREEN
if(!isset($action)){

if(@file_exists("../install/setup.php")){
	die("Installation Libraries still exist on this system.  Please delete these files in order to run the Administration Area.");
}
if(@file_exists("../upgrade/upgrade1.php")){
	die("Upgrade Libraries still exist on this system.  Please delete these files in order to run the Administration Area.");
}

	print sheader();
	/*
	$sql="SELECT * FROM ".$config->dt[templates]." WHERE name='adminlogin';";
	$result=mysql_query($sql);
	$value=mysql_fetch_array($result);
	//login template is stored in database
	$data = $value['template'];
	*/
	$data = parse(template("adminlogin"));
	//$data = parse($data);
	$data = addslashes($data);
	eval("echo stripslashes(\"$data\");");
	if(isset($mode)){
		if($mode=="debug")
			phpinfo();
	}
	print $config->copypow;
	print footer();
}//end action not set
//VERIFY & FORWARD USER
elseif($action=="load"){
	if(authenticate($HTTP_COOKIE_VARS,$HTTP_POST_VARS)){
		session_save_path($sspath);
		session_start();
		//store the information
		//$HTTP_SESSION_VARS["Suser"]=$HTTP_POST_VARS['user'];
		//$HTTP_SESSION_VARS["Spass"]=md5($HTTP_POST_VARS['pass']);
		//if(isset($user))
		//	$Suser=$user;
		//else
		//if(isset($pass))
		//	$Spass=$pass;
		//else
		global $Suser,$Spass;
		
		$Suser=$HTTP_POST_VARS['user'];
		$Spass=md5($HTTP_POST_VARS['pass']);
		
		session_register("Suser");
		session_register("Spass");
		if(is_array($HTTP_SESSION_VARS)){
			$HTTP_SESSION_VARS["Suser"]=$Suser;
			$HTTP_SESSION_VARS["Spass"]=$Spass;
		}
		elseif(is_array($_SESSION)){
			$_SESSION["Suser"]=$Suser;
			$_SESSION["Spass"]=$Spass;
		}
		$Suser=$HTTP_POST_VARS['user'];
		$Spass=md5($HTTP_POST_VARS['pass']);
		
		//print "$Suser<br>$Spass";
		//header("location: admin.php?".SID);
		redirect("admin.php?".SID);
	}
	else{
		//header("location: ".str_replace(" ","%20",$PHP_SELF));
		redirect(str_replace(" ","%20",$PHP_SELF));
	}
}
//LOG USER OUT
elseif($action=="logout"){
	session_save_path($sspath);
	session_start();
	//clear variables from the session
	session_unset();
	//kill the session
	session_destroy();
	//logged out!
	//header("location: ".str_replace(" ","%20",$PHP_SELF));
	redirect(str_replace(" ","%20",$PHP_SELF));
}


/*
	Parse the template and replace variables with values
*/
function parse($code){
	global $PHP_SELF,$config;
	$code=str_replace("{url}",$config->cs['forum_url'],$code);//$url
	$code=str_replace("{title}",$config->cs['title'],$code);//$title
	$code=str_replace("{site}",$config->cs['forum_title'],$code);//$site
	$code=str_replace("{PHP_SELF}",$PHP_SELF,$code);//$PHP_SELF
	return $code;
}
?>
